import Konva from "konva";
import { Draw } from "../../../Draw/Draw";
import { getColorMatch } from "../../../Utils";
import { TRANSFORMER_OPTION } from "../../../Config/transformer-options";

/**
 * 实现 Konva Graph 多选
 */
export function groupMultiple(draw: Draw) {
  const layer = draw.getLayer();
  if (!layer) return;

  draw.clearTransformer();
  draw.clearLineControl();

  // 目前选中的节点
  const konvaGraph = draw.getKonvaGraph();
  const selected = konvaGraph.getSelected();

  // 创建新的形变节点
  const transformerColor = <string>getColorMatch(draw, "transformerColor");
  const tr = new Konva.Transformer({
    ...TRANSFORMER_OPTION,
    anchorStroke: transformerColor,
    anchorFill: transformerColor,
    borderStroke: transformerColor,
  });

  layer.add(tr.nodes(selected));
  layer.draw();
}
